from interface.MemberInterface import MemberInterface
from utils.SendMethod import SendMethod


class ShopInterface:
    def __init__(self, url):
        self.url = url
        self.header = MemberInterface(self.url).get_token("KFC7516", "654321")

    # 添加购物车
    def add_carts(self, cart_ltem):
        method = "post"
        url = self.url + "/cart/add"
        return SendMethod.send_method(method, url, headers=self.header, json=cart_ltem)

    # 查看购物车列表
    def get_cartslist(self):
        url = self.url + "/cart/list"
        return SendMethod.send_method(method='get', url=url, headers=self.header)

    # 清空购物车
    def cart_clear(self):
        url = self.url + "/cart/clear"
        SendMethod.send_method(method='post', url=url, headers=self.header)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    shop = ShopInterface(url)
    cartltme = {
        "createDate": "2022-07-23T07:44:54.654Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 1878,
        "memberNickname": "string",
        "modifyDate": "2022-07-23T07:44:54.654Z",
        "price": 2999,
        "productAttr": '[{"key":"颜色","value":"蓝色"},{"key":"容量","value":"64G"}]',
        "productBrand": "小米",
        "productCategoryId": 19,
        "productId": 27,
        "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待 ",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
        "productSkuCode": "201808270027004",
        "productSkuId": 101,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购",
        "quantity": 1
    }
    # print(shop.add_carts(cartltme))
    # shop.cart_clear()
    print(shop.get_cartslist())
